<template>
  <div class="app-container">
    <el-form ref="storeForm" :model="storeForm" :rules="storeRules" label-width="100px">
      <el-form-item label="店铺名称:" prop="name">
        <el-input v-model="storeForm.name" placeholder="请输入店铺名称" style="width:30%" />
      </el-form-item>
      <el-form-item label="店铺地址:" prop="address">
        <el-input v-model="storeForm.address" placeholder="请输入店铺地址" style="width:50%" />
      </el-form-item>
      <el-form-item label="店铺简介:" prop="resume">
        <el-input
          v-model="storeForm.resume"
          type="textarea"
          style="width:50%"
          placeholder="请输入店铺简介"
          :autosize="{ minRows: 3, maxRows: 8}"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click.native.prevent="onSubmit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { getRestaurantInfo, updateRestaurantInfo } from '@/api/restaurant'

export default {
  data() {
    return {
      storeForm: {
        id: '',
        name: '',
        address: '',
        resume: ''
      },
      storeRules: {
        name: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }],
        address: [{ required: true, message: '请输入店铺地址', trigger: 'blur' }],
        resume: [{ required: true, message: '请输入店铺简介', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      // this.$message('查询店铺信息')
      getRestaurantInfo().then(res => {
        this.storeForm = res.data
      })
    },
    onSubmit() {
      this.$refs.storeForm.validate(valid => {
        if (valid) {
          this.$confirm('是否要进行添加操作?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            updateRestaurantInfo(this.storeForm).then(res => {
              this.$message.success('更新成功')
              this.fetchData()
            })
          })
        } else {
          this.$message.error('未填写完全')
          return false
        }
      })
    }
  }
}
</script>
<style scoped>
</style>
